<?php

namespace App\Http\Controllers;

class BaseController extends Controller
{
    private $data;

    private $code;

    private $msg;

    public function run($serviceClass, $function, $request, $extra = [])
    {
        $moduleRes = call_user_func_array(
            [new $serviceClass, $function],
            [$request, $extra]
        );
        list($this->data, $this->code, $this->msg) = $moduleRes;
    }

    public function returnSuccess($data = '', $msg = '')
    {
        $res = [
            "code" => 0,
            "data" => $data,
            "msg" => $msg
        ];

        return response()->json($res);
    }

    public function returnJson($code, $msg = '', $data = '')
    {
        $res = [
            "code" => $code,
            "data" => $data,
            "msg" => $msg
        ];
        return response()->json($res);
    }

    public function response()
    {
        $data = [
            "code" => $this->code,
            "data" => $this->data,
            "msg" => $this->msg
        ];

        return  response()->json($data,200,[],JSON_UNESCAPED_UNICODE);
    }

}
